import axios from 'axios'
import { getToken } from "@/axios/auth"

// 创建axios实例
let service = axios.create({
  baseURL: process.env.BASE_API, // api的base_url
  // timeout: 5000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
  let token=getToken();

  if(token !=null ){
    config.headers[ 'X-Access-Token' ] = token;
  }

  return config
}, error => {
  return Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
  response => {
    const res = response.data;
    return Promise.resolve(res);
  },
  error => {
    return Promise.reject(error)
  }
);

export default service
